package com.fms.dao;

import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import com.fms.model.BKCashAdvanceRegisterModel;

public class BKCashAdvanceRegisterDAO {
	
	private SqlSessionFactory sqlSessionFactory; 
	
	public BKCashAdvanceRegisterDAO(){
		sqlSessionFactory = MyBatisConnectionFactory.getSqlSessionFactory();
	}
	

	/**
	 * Returns the list of all BKCashAdvanceRegister instances from the database.
	 * @return the list of all BKCashAdvanceRegister instances from the database.
	 */
	@SuppressWarnings("unchecked")
	public List<BKCashAdvanceRegisterModel> selectAll(){

		SqlSession session = sqlSessionFactory.openSession();
		
		try {
			List<BKCashAdvanceRegisterModel> list = session.selectList("BKCashAdvanceRegister.getAll");
			return list;
		} finally {
			session.close();
		}
	}

	/**
	 * Returns a BKCashAdvanceRegister instance from the database.
	 * @param id primary key value used for lookup.
	 * @return A BKCashAdvanceRegister instance with a primary key value equals to pk. null if there is no matching row.
	 */
	public BKCashAdvanceRegisterModel selectById(int id){

		SqlSession session = sqlSessionFactory.openSession();
		
		try {
			BKCashAdvanceRegisterModel bkCashAdvanceRegister = (BKCashAdvanceRegisterModel) session.selectOne("BKCashAdvanceRegister.getBySubId",id);
			return bkCashAdvanceRegister;
		} finally {
			session.close();
		}
	}

	/**
	 * Updates an instance of BKCashAdvanceRegister in the database.
	 * @param BKCashAdvanceRegister the instance to be updated.
	 */
	public void update(BKCashAdvanceRegisterModel bkCashAdvanceRegister){

		SqlSession session = sqlSessionFactory.openSession();
		
		try {
			session.update("BKCashAdvanceRegister.update", bkCashAdvanceRegister);
			session.commit();
		} finally {
			session.close();
		}
	}

	/**
	 * Insert an instance of BKCashAdvanceRegister into the database.
	 * @param BKCashAdvanceRegister the instance to be persisted.
	 */
	public void insert(BKCashAdvanceRegisterModel bkCashAdvanceRegister){

		SqlSession session = sqlSessionFactory.openSession();
		
		try {
			session.insert("BKCashAdvanceRegister.insert", bkCashAdvanceRegister);
			session.commit();
		} finally {
			session.close();
		}
	}

	/**
	 * Delete an instance of BKCashAdvanceRegister from the database.
	 * @param id primary key value of the instance to be deleted.
	 */
	public void delete(int id){

		SqlSession session = sqlSessionFactory.openSession();
		
		try {
			session.delete("BKCashAdvanceRegister.deleteById", id);
			session.commit();
		} finally {
			session.close();
		}
	}
}
